﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;

namespace FrontEndPlus.Módulos.Seguridad
{
    public class cls_Http_Remote_Upload : cls_Remote_Upload
    {
        public cls_Http_Remote_Upload(byte[] fileData, string fileNamePath, string urlString, string usuario, string password)
            : base(fileData, fileNamePath, urlString,usuario,password)
        {

        }

        public override bool UploadFile()
        {
            byte[] postData;
            try
            {
                postData = this.FileData;
                using (WebClient client = new WebClient())
                {
                    client.Credentials = CredentialCache.DefaultCredentials;
                    client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
                    client.UploadData(this.UrlString, "PUT", postData);
                }

                return true;
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to upload", ex.InnerException);
            }

        }
    }
}